package com.link.base.base.contract.controller;

import com.link.base.base.contract.model.ContractVer;
import com.link.base.base.contract.service.ContractVerService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 合同版本
 */
@Controller
@RequestMapping("/link/contractVer")
public class ContractVerController extends BasicController<ContractVer> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private ContractVerService contractVerService;

    @Override
    public BasicService<ContractVer> getBasicService() throws Exception {
        return contractVerService;
    }

    /**
     * 定点合同复制按钮
     *
     * @param entity
     * @param session
     * @param request
     * @return
     */
    @RequestMapping(value = "/copyPointContract", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> copyPointContract(@JsonParam ContractVer entity, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>(4);
        try {
            ContractVer contractVer = contractVerService.copyPointContract(entity);
            result.put("success", true);
            //将新合同返回
            result.put("newRow", contractVer);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }


    /**
     * 框架定点合同失效
     *
     * @param entity
     * @param session
     * @param request
     * @return
     * @author 王昊
     */
    @RequestMapping(value = "/unactive", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> unactiveContract(@JsonParam ContractVer entity, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>(4);
        try {
            contractVerService.unactiveContract(entity);
            result.put("newRow", entity);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 框架定点合同审批
     *
     * @param entity
     * @param session
     * @param request
     * @return
     * @author 王昊
     */
    @RequestMapping(value = "/frameContractSubmit", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> frameContractSubmit(@JsonParam ContractVer entity, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>(4);
        try {
            contractVerService.frameContractSubmit(entity);
            result.put("newRow", entity);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }


}
